package com.orange.bridgePatterns;

import java.lang.reflect.InvocationTargetException;
import java.net.URL;

/**
 * @Description: 声音驱动管理类
 */
public class DriverManager {
    //具体驱动
    public static SoundDriver soundDriver;
    private DriverManager(){

    }

    //加载驱动的方法
    public static void loadDriver(String driverName) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        //使用反射，进行注册加载
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        Class<?> aClass = systemClassLoader.loadClass(driverName);
        Object o = aClass.getConstructor().newInstance();
        soundDriver=(SoundDriver) o;
    }
}
